package ch05.d1;

import ch04.d3.Animal;
import ch04.d3.Cat;
import ch04.d3.Dog;
import org.junit.Test;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class HomeWorkTest {


    @Test
    public void testFind() {
        // 创建一个数组，包含10个姓名字符串，例如{"张三","李四",...}
        String[] names = {"张三", "李四", "王五", "赵六", "孙七", "周八", "吴九", "郑十", "钱十一", "孔十二"};
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入要查找的姓名：");
        String name=scan.next();
//        String int boolean 标记位
        boolean flag=false; //没有找到
        for (String s : names) {// iter
            if(s.equals(name)){
                flag=true;
            }
        }

        System.out.println(flag?"找到了":"没有找到");
    }

    @Test
    public void testRandom() {
        String[] names = {"张三", "李四", "王五", "赵六", "孙七", "周八", "吴九", "郑十", "钱十一", "孔十二","克文"};
        Random r=new Random();
        int index = r.nextInt(names.length);
        System.out.println(names[index]);
    }

    @Test
    public void testCopy(){
        // 复制
        int[] a={1,2,3,4,5,6,7,8,9,10};
        int[] b;


//        for (int i = 0; i < a.length; i++) {
//            b[i]=a[i];
//        }

//        System.arraycopy(a,0,b,0,a.length);
//        System.arraycopy(a,2,b,8,5);

        b=Arrays.copyOf(a,20);



        System.out.println(Arrays.toString(a));
        System.out.println(Arrays.toString(b));

    }




}
